
#include <iostream>

#include <cppunit/extensions/HelperMacros.h>

#include "../../tuxitty/src/ContactManager.h"

class ContactManagerTest : public CppUnit::TestFixture
{
	CPPUNIT_TEST_SUITE( ContactManagerTest );

	CPPUNIT_TEST( TestLoadData );
	CPPUNIT_TEST( TestAddGroup );
	CPPUNIT_TEST( TestDeleteGroup );
	CPPUNIT_TEST( TestUpdateGroupName );
	CPPUNIT_TEST( TestAddContact );

	CPPUNIT_TEST_SUITE_END();

public:
	ContactManager* manager;


	void setUp(){
		manager = new ContactManager(_T("data"));
		manager->LoadContact();
	}

	void tearDown(){
		delete manager;
	}

	void TestLoadData(){				
		CPPUNIT_ASSERT(3 == manager->GetGroupList().size());
		CPPUNIT_ASSERT(5 == manager->GetContactMap().size());

		MsnGroup* group = manager->GetGroup(0);
		CPPUNIT_ASSERT(_T("test") == group->GetName());
		MsnContact* contact = manager->GetContact(_T("tuxitty2@hotmail.com"));
		CPPUNIT_ASSERT(_T("tuxitty2") == contact->GetName());
	}

	void TestAddGroup(){
		MsnGroup* newGroup = new MsnGroup(_T("newid"), _T("newgroup"));
		manager->AddGroup(newGroup);

		CPPUNIT_ASSERT(4 == manager->GetGroupList().size());
		CPPUNIT_ASSERT(newGroup == manager->GetGroup(_T("newid")));
	}

	void TestDeleteGroup(){
		manager->DeleteGroup(_T("testid"));

		CPPUNIT_ASSERT(NULL == manager->GetGroup(_T("testid")));
	}

	void TestUpdateGroupName()
	{
		manager->UpdateGroupName(_T("testid"), _T("newname"));

		CPPUNIT_ASSERT(_T("newname") == manager->GetGroup(_T("testid"))->GetName());
	}

	void TestAddContact()
	{
		MsnContact* newContact = new MsnContact();
		newContact->SetPassport(_T("newpassport"));
		newContact->SetID(_T("newid"));
		newContact->SetName(_T("newname"));

		manager->AddContact(newContact);

		CPPUNIT_ASSERT(newContact == manager->GetContact(_T("newpassport")));

		MsnContact* newContact2 = new MsnContact();
		newContact2->SetPassport(_T("newpassport"));
		manager->AddContact(newContact2);

		CPPUNIT_ASSERT(newContact2 == manager->GetContact(_T("newpassport")));
		CPPUNIT_ASSERT(NULL == manager->GetContactByID(_T("newid")));

	}

	void TestRemoveContact()
	{
		manager->RemoveContact(_T("testid"));

		CPPUNIT_ASSERT(NULL == manager->GetContact(_T("testpassport")));
	}
};


CPPUNIT_TEST_SUITE_REGISTRATION(ContactManagerTest);
